import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.Resource;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;


public class Main {
	
	@Resource(mappedName="jms/ConnectionFactory")
	private static ConnectionFactory connectionFactory;
	static {
		System.out.println("ConFactory");
	}

	@Resource(mappedName="jms/Queue")
	private static Queue queue;
	static {
		System.out.println("Queue");
	}
	
	
	public static void main(String[] args) {
		Logger logger = Logger.getLogger(Main.class.getName());
		logger.setLevel(Level.ALL);
		logger.info("Init");
		System.err.println("syserror");
		Connection connection = null;
		Session session = null;
		MessageProducer messageProducer = null;
		try {
			connection = connectionFactory.createConnection();
			logger.info("Connection");
			session = connection.createSession(false,
			    Session.AUTO_ACKNOWLEDGE);
			logger.info("Session");
			messageProducer = session.createProducer(queue);
			logger.info("MessageProducer");
			TextMessage message = session.createTextMessage();
			message.setText("This is a message");
			logger.info("Sending...");
			System.out.println("Sending...");
			messageProducer.send(message);
			logger.info("Sent");
			System.out.println("Done");
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (messageProducer != null) {
				try {
					messageProducer.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (session != null) {
				try {
					session.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (connection != null) {
				try {
					connection.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}

	/* (non-Java-doc)
	 * @see java.lang.Object#Object()
	 */
	public Main() {
		super();
	}

}